﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Travel.Common
{
    public static class PaginationExtention
    {
        public static IQueryable<T> ToPageList<T>(this IQueryable<T> queryCollections, int? pageIndex, int? pageSize)
        {
            int pIndex = pageIndex == null ? 1 : (int)pageIndex;
            int pSize = pageIndex == null ? 10 : (int)pageSize;

            pIndex = Math.Max(1, pIndex);
            pSize = Math.Max(0, pSize);
            return queryCollections.Skip((pIndex - 1) * pSize).Take(pSize);
        }

        public static IEnumerable<T> ToPageList<T>(this IEnumerable<T> queryCollections, int? pageIndex, int? pageSize)
        {
            int pIndex = pageIndex == null ? 0 : (int)pageIndex;
            int pSize = pageIndex == null ? 10 : (int)pageSize;

            pIndex = Math.Max(1, pIndex);
            pSize = Math.Max(0, pSize);
            return queryCollections.Skip((pIndex - 1) * pSize).Take(pSize);
        }
    }
}
